package com.wangyadong.hobby.javanetwork.uri;

import java.io.IOException;
import java.io.InputStream;
import java.net.*;

import static com.wangyadong.hobby.javanetwork.input.InputTest.readMultpileAvailable;

/**
 * <p>
 *
 * @author <714037465@qq.com>
 * @since 2019/7/1015:12
 * URI没有ASC码限制
 **/
public class URITest {

    public static void main(String[] args) throws IOException {

        testuriConstract("http");
        String decode = URLDecoder.decode("%E5%85%A8%E9%83%A8%E5%8C%BA%E5%9F%9F", "UTF-8");
        System.out.println("--" + decode);
    }

    /**
     * URI
     * scheml:schemlPart:frament
     *
     * @param urlString
     */
    public static void testuriConstract(String urlString) {
        URI url = null;
        try {
            //默认80端口
            url = new URI(urlString);
            //必须是ASC码
            url = new URI(urlString, "www.caifupad.com", "#个123");
//            url = new URI(null, "www.caifupad.com", "#123");
//            url = new URI(null, "www.caifupad.com", "/index.html", "123");
//            url = new URI("ftp:", "anonymous:elharo@ibiblio.org", null, null);
//            url = URI.create("ftp://www.caifupad.com");

            String scheme = url.getScheme();
            String schemeSpecificPart = url.getSchemeSpecificPart();
            String rawSchemeSpecificPart = url.getRawSchemeSpecificPart();
            String fragment = url.getFragment();
            String rawFragment = url.getRawFragment();
            System.out.println(" scheme " + scheme + " schemeSpecificPart " + schemeSpecificPart + " rawSchemeSpecificPart " + rawSchemeSpecificPart);
            System.out.println(" fragment " + fragment + " rawFragment " + rawFragment);
            System.out.println("================" + url.isOpaque() + url.toASCIIString());

        } catch (URISyntaxException e) {
            e.printStackTrace();
        }
    }


}
